﻿<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>异动解析</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">						
			p {margin:1px}
			ul {margin:1px}	
			li {margin:3px}			
			.fixedBox{
				border: 0px solid #555555;				
				white-space: nowrap;	
			}
			.fixedBox::-webkit-scrollbar {
				width: 10px;     
				height: 10px;				
			}			
		</style>		
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="DatePicker/WdatePicker.js"> </script>
		<script>

			const TOKEN = 'a2749745c95bd3253352746d883188ac';
            const DEFAULT_AVATAR = '';
            const DEFAULT_MEDAL = '';
            

			var xqs = 0;  //默认详情打开(= 1)或关闭(= 0)
			var dt = "";
			var tt = "";
			var gt = "";
			var time = "";			
			window.onload = function() {
				var day = new Date();
				gt = day.getTime();
				mymonth = day.getMonth()+1;
				myday = day.getDate();
				if(mymonth >= 10){mymonth = mymonth;}else{mymonth = "0" + mymonth;}
				if(myday >= 10){myday = myday;}else{myday = "0" + myday;}
				tt = day.getFullYear() + "-" + mymonth + "-" + myday;	
				dt = tt;
				time = day.getTime(dt);
				tradeday();
				getSource();
				changeStyle();
			}
			
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {								
					getSource();																		
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {				
				time_range("11:45","15:40")														
				},
				300000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");			
				obj1.style.top= "0px";	
				obj1.style.left= "0px"; 				
				obj1.style.width= "100%";	
				obj1.style.height= "100%";		
				obj1.style.fontSize= "12px";	
				//obj1.style.whiteSpace= "normal";
			}
			
			
			Date.prototype.Format = function (fmt) {
			var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
			};
			
			if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num) / 100;  
               return result;  
			};
						
			function cDayFunc(dp) { 
				pn = -1;
				var date = dp.cal.getNewDateStr();            
				BookingRmk(date);//调用其它函数并带上参数                
			}
			
			function BookingRmk(date){         
				tt = date;				
				tradeday();
				getSource();						
			}			
			
			function prev(){  //前一天
				pn = -1;
				var day = new Date(tt);	
				day.setTime(day.getTime() - 24*60*60*1000);	
				tt = day.Format("yyyy-MM-dd");
				BookingRmk(tt);				
			}
			
			function next(){  //后一天
				pn = 1;
				var day = new Date(tt);	
				day.setTime(day.getTime() + 24*60*60*1000);	
				var tt1 = day.Format("yyyy-MM-dd");
				//alert(tt1)
				var date1 = new Date(tt1);
				var date2 = new Date(dt);						
				if(date1.getTime() <= date2.getTime()){								
					tt = tt1;
					BookingRmk(tt);	
				}			
			}
			
			var pn = -1;
			function tradeday() {  //判断最后交易日
				var day = new Date(tt);
				var daydt = new Date(dt);
				
				for (i = 1; i < 100; i++){	//节假日																										
					if(i > 1){
						day.setTime(day.getTime() + pn*24*60*60*1000);							
					}	
					tt = day.Format("yyyy-MM-dd");
					//alert(tt);
					
					var url = "https://app.jiuyangongshe.com/jystock-app/api/v1/action/field"; 
					var xhr = new XMLHttpRequest();	
					var array = {"date":tt,"pc":1}						
					xhr.open("POST", url, false);				
					xhr.setRequestHeader("platform", "3");
					xhr.setRequestHeader("timestamp", time);
					xhr.setRequestHeader("token", "0");
					xhr.setRequestHeader("Content-Type", "application/json");
					xhr.setRequestHeader('Authorization', TOKEN);
					xhr.withCredentials = true
					xhr.send(JSON.stringify(array)) ; 
					var data = xhr.responseText;
					var json = JSON.parse(data);					
					json = json.data;
					
					<!-- if(pn < 0){							 -->
						<!-- if(json.length > 1){ -->
							<!-- tt = json[0].date; -->
							<!-- break; -->
						<!-- } -->
					<!-- }else{ -->
						<!-- if(tt == json[0].date){ -->
							<!-- break; -->
						<!-- }else if(day.getTime() == daydt.getTime()){ -->
							<!-- tt = json[0].date -->
							<!-- break; -->
						<!-- }					 -->
					<!-- } -->
					if (day.getTime() == daydt.getTime()){                        
                        tt = json[0].date
                        break;
                    }else if (tt == json[0].date && json.length > 1){
                        tt = json[0].date
                        break;
                    }
				}				
			}	
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
					xmlHttp = new XMLHttpRequest();					
					} else {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");					
				}
			}
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){				
					if(alist[i].id != "xq"){
						alist[i].style.color = "#E5E5E5"; //给所有a标签赋原色
					}
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
			function getSource() {				
				div = document.getElementById('towrite');
				div.innerHTML = '<font size="3" color="#FFFFFF">异动解析&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><input style="width: 90px;" type="text" id="PriceDate" name="PriceDate" class="Wdate" onFocus="WdatePicker({ onpicking: cDayFunc})" />';										
				var back = '<a href="javascript:prev();"  style="padding-left:10px;font-size:16px;color:#fff;">←</a>';				
				var forward = '<a href="javascript:next();"  style="font-size:16px;color:#fff;">→</a>';
				div.innerHTML += back + forward;
				
				var url = "https://app.jiuyangongshe.com/jystock-app/api/v1/action/field"; 	                			
				createXmlHttp();
				var array = {"date":tt,"pc":1}
				xmlHttp.onreadystatechange = writeSource;
				xmlHttp.open("POST", url, true);				
				xmlHttp.setRequestHeader("platform", "3");
                xmlHttp.setRequestHeader("timestamp", time);
                xmlHttp.setRequestHeader("token", "0");
				xmlHttp.setRequestHeader("Content-Type", "application/json");
				xmlHttp.setRequestHeader('Authorization', TOKEN);
				xmlHttp.withCredentials = true
				xmlHttp.send(JSON.stringify(array)) ; 
			}


			let bankuaiList = {};
			function writeSource() {
				if (xmlHttp.readyState == 4) { 
					var data = xmlHttp.responseText
					//document.write(data);					
					console.log(data);
					var json = JSON.parse(data);					
					json =  json.data;
					
					var div = document.getElementById('towrite');
					if(json.length > 1){
						var ids = "";
						for (var i = 1; i < json.length; i++){						
							var rc = json[i].name;
							var id = rc.replace(/\./g,"");
							if(i == 1){
								ids = "id" + id;
							}							
							var name = "<a style='color:#FFFF00;font-size:14px' href='javascript:void(0)' id='id" + id + "' onclick='update(\"" + id + "\")'>" + rc + "（" + json[i].count + "）</a>";
							// div.innerHTML += "<p style='margin-left:5px;'>" + name + "<a id='"+id+"bankuai' style='position:absolute;left:390px;display:none'> +板块 </a></p>"; 
							div.innerHTML += "<p id='id2"+id+"' style='margin-left:5px;'>" + name + "</p>"; 
							var newDiv = document.createElement("div");
							newDiv.id = id; 
							newDiv.style.display = "none";							
							div.appendChild(newDiv);
							div1 = document.getElementById(id);	
							div1.innerHTML = '<p style="width:95%;font-size:15px;color:#00FFFF;white-space:normal;">' + json[i].reason + '</p>'; 
							
							var codeStrs="";
							var aa = json[i].list;
							for (var j = 0; j < aa.length; j++){	
								var code = aa[j].code;
								var name = aa[j].name;
								var bb = aa[j].article.action_info;
								var lb = bb.num;
								codeStrs+=code;
								codeStrs+="|"; 

								if(lb == null){
									lb = "";
								}
								code = code.replace(/(sh)|(sz)|(bj)/g,"")
								var ztsj = "【" + bb.time +  "】" ;
								if(bb.time == null || bb.time ==""){
									ztsj = "";
								}
								var gg = "<a style='color:#F9F9F9;' href='http://www.treeid/code_" + code + 
								"' onclick='changeCss(this,\"" + id + "\");'>" + code + 
								"&nbsp;&nbsp;" + name + "&nbsp;&nbsp;" + lb + "&nbsp;&nbsp;" + 
								keepTwoDecimal(bb.shares_range) + "%&nbsp;&nbsp;" + ztsj + "</a>";
								var jx = "<td><a href='javascript:void(0)' id='xq' onclick='updates(" + "\"" + code + "\"" + ");' style='position:absolute;left:390px;color:#FFA07A'>" + "详情" + "</a></td>";														
								div1.innerHTML += "<li>" + gg.replace(/\[\]/g,"") + jx + "</li>";
							
								var xq = bb.expound;
								xq = xq.replace(/\n/g, "<br>");
								//添加分类Div
								var newDiv1 = document.createElement("div");
								newDiv1.id = code;
								if(xqs == 0){
									newDiv1.style.display = "none";
								}else if (xqs == 1){
									newDiv1.style.display = "block";
									newDiv1.style.width = "95%";
									newDiv1.style.border = "1px solid #646464";
									newDiv1.style.color = "#FFFACD";
									newDiv1.style.whiteSpace = "normal";
									newDiv1.style.fontSize= "14px";	
									temp1 += code + ";";
								}
								div1.appendChild(newDiv1);
								div2 = document.getElementById(code);
								div2.innerHTML += xq;
							}	

							bankuaiList[id]=codeStrs;

						}
						temp = "";	
						$("#" + ids).click();														
					}else{
						div.innerHTML += '<p><font size="3">暂无数据</font></p>';
					}
					document.getElementById("PriceDate").value = tt;
				}
			}
			
			var temp = "";	
			var temp1 = "";
			function update(ss) {	
				//alert(temp)
				if(document.getElementById(ss)){					
					div1 = document.getElementById(ss); 
					if(temp.indexOf(ss) == -1){
						temp += ss + ";";
						div1.style.display = "block";

						pp = document.getElementById("id2"+ss);  
						var blink = document.createElement('a');
						blink.id = "bankuai"+ss;
						blink.style.position = 'absolute';
						blink.style.left = "390px";
						blink.innerHTML = "+板块";
						blink.href = "http://www.treeid/AddToBlock_"+bankuaiList[ss];
						
						pp.appendChild(blink);

					}else{
						temp = temp.replace(ss + ";" , "");
						div1.style.display = "none"; 
						var aa = document.getElementById("bankuai" + ss);
						var parent = aa.parentNode;
						if (parent) {
							parent.removeChild(aa);
						}

					}
				}		
				
			
				// if(document.getElementById(ss)){					
				// 	div1 = document.getElementById(ss+"bankuai"); 
				// 	if(temp1.indexOf(ss) == -1){
				// 		temp1 += ss + ";";
				// 		div1.style.display = "block";
				// 	}else{
				// 		temp1 = temp.replace(ss + ";" , "");
				// 		div1.style.display = "none";
				// 	}
				// }
			}
			
			var temp1 = "";			
			function updates(ss) {				
				if(document.getElementById(ss)){					
					div1 = document.getElementById(ss);
					if(temp1.indexOf(ss) == -1){
						temp1 += ss + ";";
						div1.style.display = "block";
						div1.style.width = "95%";
						div1.style.border = "1px solid #646464";
						div1.style.color = "#FFFACD";
						div1.style.whiteSpace = "normal";
						div1.style.fontSize= "14px";	
					}else{
						temp1 = temp1.replace(ss + ";" , "");
						div1.style.display = "none";
					}
				}								
			}
			
		</script>
	</head>
	<body>
		<div id="towrite" class="fixedBox"></div>
	</body>
</html>